using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using ObjectLib;

namespace ObjectParser
{
	/// <summary>
	/// Summary description for FormCameraSettings.
	/// </summary>
	public class FormImageSettings : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox textFstop;
		private System.Windows.Forms.TextBox textRate;
		private System.Windows.Forms.Button butOk;
		private System.Windows.Forms.TextBox textDate;
		private System.Windows.Forms.TextBox textTime;
		private System.Windows.Forms.TextBox textGps;
		private System.Windows.Forms.TextBox textLocation;
		private System.Windows.Forms.Label labelFstop;
		private System.Windows.Forms.Label labelRate;
		private System.Windows.Forms.Label labelDate;
		private System.Windows.Forms.Label labelTime;
		private System.Windows.Forms.Label labelGps;
		private System.Windows.Forms.Label labelLocation;
		private System.Windows.Forms.TextBox textIso;
		public ObjectParserData Opd;
		private System.Windows.Forms.Label labelIso;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormImageSettings(ObjectParserData Opd)
		{
			InitializeComponent();

			this.DialogResult = DialogResult.Cancel;

			this.Opd = Opd;

			textFstop.Text = Convert.ToString(Opd.Fstop);
			textRate.Text = Convert.ToString(Opd.ShutterRate);
			textIso.Text = Opd.IsoFilmSpeed.ToString();
			if(Opd.CapturedAt!=DateTime.MinValue)
			{
				textDate.Text = Convert.ToString(Opd.CapturedAt.ToString("d"));
				textTime.Text = Convert.ToString(Opd.CapturedAt.ToString("H:m:s"));
			}
			else
			{
				textDate.Text = "";
				textTime.Text = "";
			}
			textGps.Text = Opd.Gps;
			textLocation.Text = Opd.Location;
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.labelFstop = new System.Windows.Forms.Label();
			this.labelRate = new System.Windows.Forms.Label();
			this.textFstop = new System.Windows.Forms.TextBox();
			this.textRate = new System.Windows.Forms.TextBox();
			this.butOk = new System.Windows.Forms.Button();
			this.textDate = new System.Windows.Forms.TextBox();
			this.labelDate = new System.Windows.Forms.Label();
			this.labelTime = new System.Windows.Forms.Label();
			this.textTime = new System.Windows.Forms.TextBox();
			this.textGps = new System.Windows.Forms.TextBox();
			this.labelGps = new System.Windows.Forms.Label();
			this.textLocation = new System.Windows.Forms.TextBox();
			this.labelLocation = new System.Windows.Forms.Label();
			this.textIso = new System.Windows.Forms.TextBox();
			this.labelIso = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// labelFstop
			// 
			this.labelFstop.Location = new System.Drawing.Point(8, 16);
			this.labelFstop.Name = "labelFstop";
			this.labelFstop.Size = new System.Drawing.Size(120, 16);
			this.labelFstop.TabIndex = 0;
			this.labelFstop.Text = "F-stop";
			this.labelFstop.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// labelRate
			// 
			this.labelRate.Location = new System.Drawing.Point(8, 40);
			this.labelRate.Name = "labelRate";
			this.labelRate.Size = new System.Drawing.Size(120, 16);
			this.labelRate.TabIndex = 1;
			this.labelRate.Text = "Shutter Rate (Hz)";
			this.labelRate.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textFstop
			// 
			this.textFstop.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textFstop.Location = new System.Drawing.Point(128, 16);
			this.textFstop.Name = "textFstop";
			this.textFstop.Size = new System.Drawing.Size(176, 20);
			this.textFstop.TabIndex = 0;
			this.textFstop.Text = "";
			// 
			// textRate
			// 
			this.textRate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textRate.Location = new System.Drawing.Point(128, 40);
			this.textRate.Name = "textRate";
			this.textRate.Size = new System.Drawing.Size(176, 20);
			this.textRate.TabIndex = 1;
			this.textRate.Text = "";
			// 
			// butOk
			// 
			this.butOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.butOk.Location = new System.Drawing.Point(232, 192);
			this.butOk.Name = "butOk";
			this.butOk.TabIndex = 6;
			this.butOk.Text = "OK";
			this.butOk.Click += new System.EventHandler(this.butOk_Click);
			// 
			// textDate
			// 
			this.textDate.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textDate.Location = new System.Drawing.Point(128, 88);
			this.textDate.Name = "textDate";
			this.textDate.Size = new System.Drawing.Size(176, 20);
			this.textDate.TabIndex = 2;
			this.textDate.Text = "";
			// 
			// labelDate
			// 
			this.labelDate.Location = new System.Drawing.Point(8, 88);
			this.labelDate.Name = "labelDate";
			this.labelDate.Size = new System.Drawing.Size(120, 16);
			this.labelDate.TabIndex = 5;
			this.labelDate.Text = "Date (M/D/Y)";
			this.labelDate.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// labelTime
			// 
			this.labelTime.Location = new System.Drawing.Point(8, 112);
			this.labelTime.Name = "labelTime";
			this.labelTime.Size = new System.Drawing.Size(120, 16);
			this.labelTime.TabIndex = 7;
			this.labelTime.Text = "Military Time (H:M:S)";
			this.labelTime.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textTime
			// 
			this.textTime.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textTime.Location = new System.Drawing.Point(128, 112);
			this.textTime.Name = "textTime";
			this.textTime.Size = new System.Drawing.Size(176, 20);
			this.textTime.TabIndex = 3;
			this.textTime.Text = "";
			// 
			// textGps
			// 
			this.textGps.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textGps.Location = new System.Drawing.Point(128, 136);
			this.textGps.Name = "textGps";
			this.textGps.Size = new System.Drawing.Size(176, 20);
			this.textGps.TabIndex = 4;
			this.textGps.Text = "";
			// 
			// labelGps
			// 
			this.labelGps.Location = new System.Drawing.Point(8, 136);
			this.labelGps.Name = "labelGps";
			this.labelGps.Size = new System.Drawing.Size(120, 16);
			this.labelGps.TabIndex = 9;
			this.labelGps.Text = "GPS";
			this.labelGps.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textLocation
			// 
			this.textLocation.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textLocation.Location = new System.Drawing.Point(128, 160);
			this.textLocation.Name = "textLocation";
			this.textLocation.Size = new System.Drawing.Size(176, 20);
			this.textLocation.TabIndex = 5;
			this.textLocation.Text = "";
			// 
			// labelLocation
			// 
			this.labelLocation.Location = new System.Drawing.Point(8, 160);
			this.labelLocation.Name = "labelLocation";
			this.labelLocation.Size = new System.Drawing.Size(120, 16);
			this.labelLocation.TabIndex = 11;
			this.labelLocation.Text = "Location";
			this.labelLocation.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textIso
			// 
			this.textIso.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.textIso.Location = new System.Drawing.Point(128, 64);
			this.textIso.Name = "textIso";
			this.textIso.Size = new System.Drawing.Size(176, 20);
			this.textIso.TabIndex = 13;
			this.textIso.Text = "";
			// 
			// labelIso
			// 
			this.labelIso.Location = new System.Drawing.Point(8, 64);
			this.labelIso.Name = "labelIso";
			this.labelIso.Size = new System.Drawing.Size(120, 16);
			this.labelIso.TabIndex = 12;
			this.labelIso.Text = "ISO Film Speed";
			this.labelIso.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// FormImageSettings
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(312, 222);
			this.Controls.Add(this.textIso);
			this.Controls.Add(this.labelIso);
			this.Controls.Add(this.butOk);
			this.Controls.Add(this.textLocation);
			this.Controls.Add(this.labelLocation);
			this.Controls.Add(this.textGps);
			this.Controls.Add(this.labelGps);
			this.Controls.Add(this.textTime);
			this.Controls.Add(this.labelTime);
			this.Controls.Add(this.textDate);
			this.Controls.Add(this.labelDate);
			this.Controls.Add(this.textRate);
			this.Controls.Add(this.textFstop);
			this.Controls.Add(this.labelRate);
			this.Controls.Add(this.labelFstop);
			this.Name = "FormImageSettings";
			this.Text = "Image Settings";
			this.ResumeLayout(false);

		}
		#endregion

		private void butOk_Click(object sender, System.EventArgs e)
		{
			float fstop=0.0f,  shutterRate=0.0f, iso=0.0f;
			DateTime dt = DateTime.MinValue;
			bool proceed = true;

			try
			{
				fstop = Convert.ToSingle(textFstop.Text);
				labelFstop.Refresh();
				labelFstop.ForeColor = Color.Black;
			}
			catch
			{
				labelFstop.ForeColor = Color.Red;
				labelFstop.Refresh();
				proceed = false;
			}
			try
			{
				shutterRate = Convert.ToSingle(textRate.Text);
				labelRate.ForeColor = Color.Black;
				labelRate.Refresh();
			}
			catch
			{
				labelRate.ForeColor = Color.Red;
				labelRate.Refresh();
				proceed = false;
			}
			try
			{
				iso = Convert.ToSingle(textIso.Text);
				labelIso.ForeColor = Color.Black;
				labelIso.Refresh();
			}
			catch
			{
				labelIso.ForeColor = Color.Red;
				labelIso.Refresh();
				proceed = false;
			}
			if(textDate.Text.Length>0 || textTime.Text.Length>0)
			{
				try
				{
					dt = DateTime.Parse(textDate.Text + " " + textTime.Text);
					labelDate.ForeColor = Color.Black;
					labelTime.ForeColor = Color.Black;
					labelDate.Refresh();
					labelTime.Refresh();
				}
				catch
				{
					labelDate.ForeColor = Color.Red;
					labelDate.Refresh();
					labelTime.ForeColor = Color.Red;
					labelTime.Refresh();
					proceed = false;
				}
			}
			if(proceed)
			{
				Opd.Fstop = fstop;
				Opd.ShutterRate = shutterRate;
				Opd.IsoFilmSpeed = iso;
				if(textDate.Text.Length>0 || textTime.Text.Length>0)
					Opd.CapturedAt = dt;
				Opd.Gps = textGps.Text;
				Opd.Location = textLocation.Text;

				this.DialogResult = DialogResult.OK;
				this.Close();
			}
		}
	}
}
